package online.sixfish.doubao.controller.admin;

import online.sixfish.common.api.ApiResult;
import online.sixfish.doubao.model.dto.AddNoticeDTO;
import online.sixfish.doubao.model.dto.PageDTO;
import online.sixfish.doubao.model.dto.QueryNoticeDTO;
import online.sixfish.doubao.model.entity.Notice;
import online.sixfish.doubao.service.admin.AdminNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class AdminNoticeController {
    @Resource
    AdminNoticeService adminNoticeService;

    @PostMapping("/admin/notice/add")
    @PreAuthorize("hasRole('admin')")
    public ApiResult addNotice(@RequestBody AddNoticeDTO addNoticeDTO){
        adminNoticeService.addNotice(addNoticeDTO);
        return ApiResult.success();
    }

    @PostMapping("/admin/notice/update")
    @PreAuthorize("hasRole('admin')")
    public ApiResult updateNotice(@RequestBody Notice notice){
       adminNoticeService.updateNotice(notice);
        return ApiResult.success();
    }


   @PostMapping("/admin/notice/list")
   @PreAuthorize("hasRole('admin')")
    public ApiResult listNotice(@RequestBody QueryNoticeDTO queryNoticeDTO){
       PageDTO pageDTO = adminNoticeService.listNotice(queryNoticeDTO);
       return ApiResult.success(pageDTO);
   }
}
